package com.bh.web.controller.base;

import com.bh.base.domain.JcKyRegistration;
import com.bh.base.service.IJcRegistrationService;
import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.core.page.TableDataInfo;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.poi.ExcelUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 注册机构Controller
 * 
 * @author slx
 * @date 2023-11-12
 */
@RestController
@RequestMapping("/base/registration")
public class JcRegistrationController extends BaseController
{
    @Autowired
    private IJcRegistrationService jcRegistrationService;

    /**
     * 查询注册机构列表
     */
    @ApiOperation("查询注册机构列表")
    @PreAuthorize("@ss.hasPermi('base:registration:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcKyRegistration jcRegistration)
    {
        startPage();
        List<JcKyRegistration> list = jcRegistrationService.selectJcRegistrationList(jcRegistration);
        return getDataTable(list);
    }

    /**
     * 导出注册机构列表
     */
    @PreAuthorize("@ss.hasPermi('base:registration:export')")
    @Log(title = "注册机构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcKyRegistration jcRegistration)
    {
        List<JcKyRegistration> list = jcRegistrationService.selectJcRegistrationList(jcRegistration);
        ExcelUtil<JcKyRegistration> util = new ExcelUtil<JcKyRegistration>(JcKyRegistration.class);
        util.exportExcel(response, list, "注册机构数据");
    }

    /**
     * 获取注册机构详细信息
     */
    @ApiOperation("获取注册机构详细信息")
    @PreAuthorize("@ss.hasPermi('base:registration:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jcRegistrationService.selectJcRegistrationById(id));
    }

    /**
     * 新增注册机构
     */
    @ApiOperation("新增注册机构")
    @PreAuthorize("@ss.hasPermi('base:registration:add')")
    @Log(title = "注册机构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcKyRegistration jcRegistration)
    {
        return toAjax(jcRegistrationService.insertJcRegistration(jcRegistration));
    }

    /**
     * 修改注册机构
     */
    @ApiOperation("修改注册机构")
    @PreAuthorize("@ss.hasPermi('base:registration:edit')")
    @Log(title = "注册机构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcKyRegistration jcRegistration)
    {
        return toAjax(jcRegistrationService.updateJcRegistration(jcRegistration));
    }

    /**
     * 删除注册机构
     */
    @ApiOperation("删除注册机构")
    @PreAuthorize("@ss.hasPermi('base:registration:remove')")
    @Log(title = "注册机构", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jcRegistrationService.deleteJcRegistrationByIds(ids));
    }
}
